package com.kehao.leetcode.basic.dp;

import org.junit.Test;

public class DPSolution1 {

    public int climbStairs(int n) {
//        方法一
//        if(n==1) return 1;
//        int[] answer= new int[n];
//        answer[0] = 1;
//        answer[1] = 2;
//        for (int i = 2; i < n; i++) {
//            answer[i] = answer[i-1]+answer[i-2];
//        }
//        return answer[n-1];

//        方法二
        int answer1 = 1;
        int answer2 = 2;
        int answer = 0;
        if(n<=2) return n;
        for (int i = 2; i < n; i++) {
            answer = answer1+answer2;
            answer1 = answer2;
            answer2 = answer;
        }
        return answer;
    }

    @Test
    public void test01(){
        System.out.println(climbStairs(3));
    }
}
